<template>
	<view class="addtebox">
		<view class="">
			<view class="teamna">队伍名称</view>
			<input class="teinp" type="text" placeholder="请输入队伍名称" v-model="teamname" />
		</view>
		<view class="addbutt" @click="cnaddte">创建队伍</view>
	
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue';
	import request from '../../utils/request';
	onMounted(() => {
		token.value = uni.getStorageSync('token')
		const options = getCurrentPages().pop().options;
		if (options && options.id) {
			venueId.value = decodeURIComponent(options.id);
		}
	})
	let token = ref()
	let venueId = ref()
	const show = ref(false);
	let teamname = ref('')
	const cancel = () => {
		show.value = false
	}
	const close = () => {
		show.value = false
	}
	const cnaddte = () => {
		if (teamname.value == '') {
			uni.$u.toast('请输入队伍名称');
		} else {
			request.post('Teams/create', {
				data: {
					competitions_id: venueId.value,
					name: teamname.value
				},
				header: {
					"token": token.value
				}
			}).then(res => {
				console.log(res);
				if (res.code == 1) {
					uni.$u.toast('保存成功');
					setTimeout(() => {
						uni.navigateBack()
					}, 2000)
				} else if (res.code == 0) {
					uni.$u.toast('您已参加该比赛');
					setTimeout(() => {
						uni.navigateBack()
					}, 2000)
				}
			}).catch(err => {
				console.log(err);
			})
		}
	}
</script>

<style scoped>
	.teamna {
		width: 100%;
		height: 80rpx;
		font-size: 14px;
		padding-left: 30rpx;
		line-height: 80rpx;
		box-sizing: border-box;
	}

	.teinp {
		width: 100%;
		height: 80rpx;
		font-size: 14px;
		padding-left: 30rpx;
		border-bottom: 1px solid #dedede;
		box-sizing: border-box;
	}

	.addbutt {
		width: 609rpx;
		height: 90rpx;
		margin: 0 auto;
		line-height: 90rpx;
		color: #fff;
		text-align: center;
		background-color: #10c696;
		margin-top: 240rpx;
		border-radius: 50rpx;
	}

</style>